package com.aiti.lulian.service.impl;

import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.entity.LuLianEnterprise;
import com.aiti.lulian.entity.LuLianEnterpriseUser;
import com.aiti.lulian.mapper.LuLianEnterpriseUserMapper;
import com.aiti.lulian.service.ILuLianEnterpriseExtensionService;
import com.aiti.lulian.service.ILuLianEnterpriseUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Author WongMz
 * @CreateDate 2024-08-29
 * @Description: 企业用户关系服务层实现类
 */
@Service
public class LuLianEnterpriseUserServiceImpl extends BaseSerivceImpl<LuLianEnterpriseUserMapper, LuLianEnterpriseUser> implements ILuLianEnterpriseUserService {

    private final LuLianEnterpriseUserMapper luLianEnterpriseUserMapper;

    private final ILuLianEnterpriseExtensionService luLianEnterpriseExtensionService;

    public LuLianEnterpriseUserServiceImpl(LuLianEnterpriseUserMapper luLianEnterpriseUserMapper, ILuLianEnterpriseExtensionService luLianEnterpriseExtensionService) {
        this.luLianEnterpriseUserMapper = luLianEnterpriseUserMapper;
        this.luLianEnterpriseExtensionService = luLianEnterpriseExtensionService;
    }

    @Override
    public Message queryEnterpriseIdByUserId(String userId){
        LuLianEnterpriseUser enterpriseUser = this.getOne(new QueryWrapper<LuLianEnterpriseUser>().eq("user_id", userId));
        if(enterpriseUser == null){
            return Message.fail();
        }
        return Message.success(enterpriseUser.getEnterpriseId());
    }

    /**
     * 查询当前用户下关联的企业信息
     *
     * @param userId
     */
    @Override
    public LuLianEnterprise selectCurrentUserJoinEnterpriseInfo(String userId) {
        return luLianEnterpriseUserMapper.selectCurrentUserJoinEnterpriseInfo(userId);
    }

    @Override
    public List<LuLianEnterpriseUser> selectUserIdToEnterpriseName(Set<String> userId) {
        List<LuLianEnterpriseUser> r = luLianEnterpriseUserMapper.selectUserIdToEnterpriseName(userId);
        return r;
    }

    @Override
    public Integer selectEnterpriseCountByUserId(String userId) {
        return luLianEnterpriseUserMapper.selectEnterpriseCountByUserId(userId);
    }

//    @Override
//    public Message getEnterpriseInfoByUserId(String userId) {
//        LuLianEnterpriseUser luLianEnterpriseUser = this.getOne(new LambdaQueryWrapper<LuLianEnterpriseUser>().eq(LuLianEnterpriseUser::getUserId, userId));
//        String enterpriseId = luLianEnterpriseUser.getEnterpriseId();
//        LuLianEnterpriseExtension enterpriseExtension = luLianEnterpriseExtensionService.getOne(new LambdaQueryWrapper<LuLianEnterpriseExtension>().eq(LuLianEnterpriseExtension::getEnterpriseId, enterpriseId));
//        Map<String, String> resultMap = new HashMap<>();
//        resultMap.put("pubBackgroundStyle", enterpriseExtension == null ? "" : enterpriseExtension.getPubBackgroundStyle());
//        resultMap.put("pubBackgroundUrl", enterpriseExtension == null ? "" : enterpriseExtension.getPubBackgroundUrl());
//        return Message.success(resultMap);
//    }
}